package com.cy.ppj.dao.mapper.user;

import com.cy.ppj.model.domian.user.UserRecommender;
import com.cy.ppj.model.dto.recommender.UserRecommenderDTO;
import com.cy.ppj.model.enums.account.BrokerLevel;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.BaseMapper;

/**
 * @description: 推荐人
 * @author: Ocean
 * @create: 2018-07-19 20:32
 **/
@Mapper
public interface UserRecommenderMapper extends BaseMapper<UserRecommender> {

    @Select(" SELECT r.recommend_user_id AS firstUserRecommender,r2.recommend_user_id AS secondUserRecommender FROM t_user_recommender r LEFT JOIN t_user_recommender r2 ON r.recommend_user_id=r2.user_id WHERE r.user_id=#{userId} ")
    UserRecommenderDTO selectRecommenderRelation(@Param("userId") Long userId);

    @Select(" SELECT u.id AS firstUserRecommender,r.recommend_user_id AS secondUserRecommender FROM t_user u LEFT JOIN t_user_recommender r ON r.user_id=u.id WHERE u.mobile=#{mobile} and u.real_auth = 1 ")
    UserRecommenderDTO selectRecommenderRelationByMobile(@Param("mobile") String mobile);

    /**
     * 查找当前用户的上级用户
     * @param userId
     * @return com.cy.ppj.model.dto.recommender.UserRecommenderDTO
     */
    UserRecommenderDTO selectUserRecommenderByUserId(@Param("userId") Long userId);

    /**
     * 查找当前用户的上级的下级的某个级别的人数
     * @param recommendUserId
     * @param level
     * @return int
     */
    int selectCountByRecommendUserIdAndLevel(@Param("recommendUserId") Long recommendUserId, @Param("level") BrokerLevel level);
}
